package com.ruoyi.web.controller.biz;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.biz.model.req.BizPwdReq;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.biz.domain.BizPwd;
import com.ruoyi.biz.service.BizPwdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 密码管理Controller
 *
 * @author tianl
 * @date 2025-02-08
 */
@RestController
@RequestMapping("/biz/bizPwd")
public class BizPwdController extends BaseController {
    @Autowired
    private BizPwdService bizPwdService;

    /**
     * 密码管理全部列表
     */
    @GetMapping(value = "/listAll")
    public AjaxResult listAll(BizPwdReq bizPwd) {
        return success(bizPwdService.list(bizPwd));
    }

    /**
     * 查询密码管理列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BizPwdReq bizPwd) {
        return getDataTable(bizPwdService.listPage(bizPwd));
    }

    /**
     * 导出密码管理列表
     */

    @Log(title = "密码管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPwdReq bizPwd) {
        List<BizPwd> list = bizPwdService.list(bizPwd);
        ExcelUtil<BizPwd> util = new ExcelUtil<>(BizPwd.class);
        util.exportExcel(response, list, "密码管理数据");
    }

    /**
     * 获取密码管理详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizPwdService.selectById(id));
    }

    /**
     * 新增密码管理
     */

    @Log(title = "密码管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPwd bizPwd) {
        bizPwdService.beforeSave(bizPwd);
        return AjaxResult.success();
    }

    /**
     * 修改密码管理
     */

    @Log(title = "密码管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPwd bizPwd) {
        bizPwdService.beforeSave(bizPwd);
        return AjaxResult.success();
    }

    /**
     * 删除密码管理
     */

    @Log(title = "密码管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizPwdService.deleteByIds(Arrays.asList(ids)));
    }
}
